<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button>1</button>
    <button>2</button>
    <button>3</button>
    <button>4</button>
    <script>
        var btn = document.querySelectorAll('button');
        for (var i = 0; i < btn.length; i++) {
            (function (j) {
                btn[j].onclick = function () {
                    console.log(j)
                };
            })(i);
        }

        function jie(n) {
            var x = 1;
            for (var i = 0; i <= n; i++) {
                x *= i
            }
            return x;
        }
        console.log(jie(5));

        function jie1(n) {
            if (n == 1) return 1;
            return n * jie1(n - 1);
        }
        console.log(jie1(4));
    </script>
</body>

</html>